﻿using System;
using System.Diagnostics;
using System.Globalization;
using System.Net;
using Newtonsoft.Json.Linq;
using WeiboPlus.Models;
using WeiboPlus.Service;

namespace WeiboPlus.Tencent
{
    public class TencentJTokenToCountMapping : MappingBase<JToken, SNSCounts>
    {
        public TencentJTokenToCountMapping(IMappingFactory factory)
            : base(factory)
        {

        }

        public override SNSCounts Map(JToken s)
        {
            try
            {
#if Debug
                    Debug.WriteLine(s);
#endif
                SNSCounts count = new SNSCounts();

                if (s.SelectToken("mentions") != null)
                    count.Mentions = (int)s.SelectToken("mentions");

                if (s.SelectToken("fans") != null)
                    count.Followers = (int)s.SelectToken("fans");

                if (s.SelectToken("home") != null)
                    count.Status = (int)s.SelectToken("home");

                if (s.SelectToken("private") != null)
                    count.PrivateMessage = (int)s.SelectToken("private");

                return count;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                throw ex;
            }
        }

    }
}
